package yxy.game.pm2.command.kow;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.KowMessage;
import yxy.game.pm2.module.kow.KowHandle;
import yxy.game.pm2.module.kow.KowHandle.KowFinalCode;

/** 天下第一 天下第一淘汰赛支持 */
@MessageType(proto = Command.KowFinalFan, classtype = KowMessage.KowFinalFanRequest.class)
public class CMD_KowFinalFan extends Command<KowMessage.KowFinalFanRequest> {

	@Override
	public void execute(MessageSource messageSource, KowMessage.KowFinalFanRequest request) {
		String playerCode = messageSource.getTag();
		KowFinalCode finalCode = KowFinalCode.forNumber(request.getFinalCode().getNumber());
		String fanCode = request.getCode();

		KowMessage.KowFinalFanResponse.Builder response = KowMessage.KowFinalFanResponse.newBuilder();

		Result result = new KowHandle().fan(playerCode, fanCode, finalCode, response);

		send(messageSource, response, result);
	}

	private void send(MessageSource messageSource, KowMessage.KowFinalFanResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}